package com.kingre.et.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.time.DateFormatUtils;

@Entity
@Table(name = "t_consult")
public class Consult extends BaseObject implements Serializable {
    private static final long serialVersionUID = -1542317276826363753L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne(targetEntity = User.class)
    @JoinColumn(name = "user_id")
    private User user;

    @Column(name = "user_tel", nullable = false, length = 32)
    private String userTel;

    @Column(name = "action_time", nullable = false)
    private Date actionTime;

    // 10预约学校老师；20预约专家
    @Column(name = "action_type", nullable = false)
    private Integer actionType;

    @ManyToOne(targetEntity = School.class)
    @JoinColumn(name = "school_id")
    private School school;

    @ManyToOne(targetEntity = User.class)
    @JoinColumn(name = "export_user_id")
    private User export;

    // 10未接受咨询；20已接受咨询；30删除
    @Column(name = "status_code", nullable = false)
    private Integer statusCode;

    public Integer getId() {
        return id;
    }

    public User getUser() {
        return user;
    }

    public String getUserTel() {
        return userTel;
    }

    public Date getActionTime() {
        return actionTime;
    }

    public Integer getActionType() {
        return actionType;
    }

    public School getSchool() {
        return school;
    }

    public User getExport() {
        return export;
    }

    public Integer getStatusCode() {
        return statusCode;
    }

    @Transient
    public String getAcDate() {
        return DateFormatUtils.format(actionTime, "yyyy-MM-dd hh:mm");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Consult)) {
            return false;
        }
        final Consult questionnaire = (Consult) o;
        return this.hashCode() == questionnaire.hashCode();
    }

    @Override
    public int hashCode() {
        int result;
        result = (id != null ? id.hashCode() : 0);
        result = 29 * result + (user != null ? user.hashCode() : 0);
        result = 29 * result + (userTel != null ? userTel.hashCode() : 0);
        result = 29 * result + (actionTime != null ? actionTime.hashCode() : 0);
        result = 29 * result + (actionType != null ? actionType.hashCode() : 0);
        result = 29 * result + (statusCode != null ? statusCode.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", id).append("user", user.toString())
                .append("userTel", userTel).append("actionTime", actionTime).append("actionType", actionType)
                .append("statusCode", statusCode).toString();
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setUserTel(String userTel) {
        this.userTel = userTel;
    }

    public void setActionTime(Date actionTime) {
        this.actionTime = actionTime;
    }

    public void setActionType(Integer actionType) {
        this.actionType = actionType;
    }

    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }

    public void setSchool(School school) {
        this.school = school;
    }

    public void setExport(User export) {
        this.export = export;
    }

}
